package com.hos.check.util;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;

public class BeanConver {
	
	/**
	 * 简单封装，没有对集合类型特殊处理
	 * 
	 * @param <T>
	 * @param request
	 * @param clazz
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	@SuppressWarnings("unchecked")
	public static <T> T converReqToBean(HttpServletRequest request,
			Class<T> clazz) throws InstantiationException,
			IllegalAccessException, InvocationTargetException {

		Map<String, String> parameters = request.getParameterMap();
		T bean = clazz.newInstance();
		BeanUtils.populate(bean, parameters);
		return bean;
	}
	
}
